from lxml import etree
from lxml.builder import E
import logging
_logging = logging.getLogger(__name__)
xml = etree.parse('./ir_ui_view.xml')
root = xml.getroot()


def generate_views_xml(root):
    # for record in root:
    for active in root.xpath("//field[@name='active']"):
        active.getparent().remove(active)
    for field_parent in root.xpath("//field[@name='field_parent']"):
        field_parent.getparent().remove(field_parent)
    for key in root.xpath("//field[@name='key']"):
        key.getparent().remove(key)
    for mode in root.xpath("//field[@name='mode']"):
        mode.getparent().remove(mode)
    for ttype in root.xpath("//field[@name='type']"):
        ttype.getparent().remove(ttype)

    xml = etree.tostring(root, pretty_print=True,
                         encoding='UTF-8', xml_declaration=True)
    # print(xml)
    return xml


generate_views_xml(root)
